package com.uam.core.tool;

/**
 * 经纬度与xy坐标转换工具类
 * @author Administrator
 */
public class LatlngXyzConvertHelper {
    /**
     *  TODO
     * @author heguanglong
     * @param lon 需要转换的经度
     * @param lat 需要转换的纬度
     * @date 2021/5/6
     * @return
    **/
    public static double[] latLngToTile(double lon, double lat) {
        double x = (float) ((lon + 180.0) / 360.0);
        double y = (float) ((1.0 - Math.log(Math.tan(lat * Math.PI / 180.0) + 1.0 / Math.cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0);
        double[] doubles = new double[2];
        doubles[0] = x;
        doubles[1] = y;
        return doubles;
    }


    /**
     *  TODO
     * @author heguanglong
     * @param tileX 需要转换的x坐标
     * @param tileY 需要转换的y坐标
     * @date 2021/5/6
     * @return
     **/
    public static double[] tileToLatLon(double tileX, double tileY) {
        double n = Math.PI - ((2.0 * Math.PI * tileY) / Math.pow(2.0, 0));
        double lng = (float) ((tileX / Math.pow(2.0, 0) * 360.0) - 180.0);
        double lat = (float) (180.0 / Math.PI * Math.atan(Math.sinh(n)));
        double[] doubles = new double[2];
        doubles[0] = lng;
        doubles[1] = lat;
        return doubles;
    }

    /**
     *  角度转换为弧度
     * @author heguanglong
     * @param degrees 距离
     * @param
     * @date 2021/5/6
     * @return
     **/
    private static double toRadians(double degrees) {
        return (Math.PI / 180) * degrees;
    }
}
